<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>查询平台</title>
    <script src="../../static/layui/layui.js"></script>
    <link rel="stylesheet" href="/static/module/login1.css">
    <script>
        layui.config({
            base: '/static/module/' //你存放新模块的目录，注意，不是layui的模块目录
        });
    </script>
    <style type="text/css">

        .loginRequired{
            margin-top: 20px;
            margin-left:20px;
            color: red;
            font-size: 16px;
        }

        .loginHidden{
            display: none;
        }
    </style>
</head>
<body>
<div class="login dp_table">
    <div class="center dp_table_cell">
        <div class="login-form dp_table">
            <div class="dp_table_cell">
                <h1>查询平台</h1>
                <h2>QUERY PLATFORM</h2>
                <form method="post" id="loginForm" action="/login/confirm">
                    <div class="line">
                        <div class="input">
                            <i><img src="/static/img/user.png"></i>
                            <input name="username" type="text" placeholder="请输入账号" >
                        </div>
                        <div id="nameRequired" class="loginRequired loginHidden">请填写账号</div>
                    </div>
                    <div class="line">
                        <div class="input">
                            <i><img src="/static/img/pwd.png"></i>
                            <input id="password" type="password" placeholder="请输入密码">
                        </div>
                        <div id="pwdRequired" class="loginRequired loginHidden">请填写密码</div>
                    </div>
                    <div class="line">
                        <button class="submit">登录</button>
                    </div>
                </form>
                <div id="loginError" class="loginRequired loginHidden">您的账号或密码有误!</div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script>
    layui.use(['global', 'sha256.min', 'jquery.form.min'], function () {
        var $ = layui.$;
        $('#loginForm').ajaxForm({
            data: {
                password: function () {
                    var loginSeed = null;
                    $.ajax({
                        url :'/login/token',
                        data:{},
                        async : false,
                        success:function (data) {
                            if (data.success) {
                                loginSeed = data.data;
                            }
                        }
                    });
                    var password = sha256(sha256($('#password').val()) + loginSeed);
                    $(this).clearForm();
                    return password;
                },
                appCode: '${appCode!''}',
                targetUrl: '${targetUrl!'/'}'
            },
            success: function (data) {
                if (data.success) {
                    if ('${targetUrl!'/'}'.indexOf('?') >= 0) {
                        window.location.href = '${targetUrl!'/'}' + '&token_enc='+data.data;
                    } else {
                        window.location.href = '${targetUrl!'/'}' + '?token_enc='+data.data;
                    }
                } else {
                    layer.msg(data.message, {
                        time:2000
                    });
                }
            }
        });
        $('#btn-register').click(function () {
            layer.msg('请联系管理员注册', {
                time:2000
            });
        });
        $('#forget_password').click(function () {
            layer.msg('请联系管理员重置密码', {
                time:2000
            })
        });

    });
    window.onload = function() {
        if(self !== top && getQueryString('r') !== '1'){
            if (window.location.href.indexOf('?') >= 0) {
                window.parent.location.href = window.location.href + "&r=1";
            } else {
                window.parent.location.href = window.location.href + "?r=1";
            }
        }
    };
    function getQueryString(name) {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
</script>
